package main.com.oaer.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import main.com.oaer.common.HibernateDaoUtil;
import main.com.oaer.dao.RolePurviewDao;
import main.com.oaer.model.RolePurview;

@Repository
public class RolePurviewDaoImpl implements RolePurviewDao {

	@Autowired
	private  HibernateDaoUtil hibernateDaoUtil;
	
	@Override
	public void add(RolePurview rolePurview) {
		if(rolePurview!=null){
			hibernateDaoUtil.save(rolePurview);
		}
	}

	@Override
	public List<RolePurview> findRolePurviewByRoleId(Long roleId) {
		if(roleId==null) return null;
		String hql = "from " +
				" RolePurview rolePurview " +
				" where " +
				" rolePurview.roleId=?";
		return hibernateDaoUtil.findListByHQL(hql,roleId);
	}

	@Override
	public void delete(RolePurview rolePurview) {
		if(rolePurview!=null){
			hibernateDaoUtil.delete(rolePurview);

		}
	}

	@Override
	public void deleteByRoleId(Long roleId) {
		if(roleId!=null){
			String hql = "delete from " +
			" RolePurview rolePurview " +
			" where " +
			" rolePurview.roleId=?";
	        hibernateDaoUtil.executeUpdateByHQL(hql, roleId);
		}
	}

	@Override
	public void deleteByPurviewId(Long purviewId) {
		if(purviewId!=null){
			String hql = "delete from " +
			" RolePurview rolePurview " +
			" where " +
			" rolePurview.purviewId=?";
	        hibernateDaoUtil.executeUpdateByHQL(hql, purviewId);
		}
	}

}
